export const defaultScore = {
  logistics: [
    { name: 'successTakeoff', score: 1 },
    { name: 'aiObjectRecognition', score: 1 },
    { name: 'obstaclePass', score: 1 },
    { name: 'supplyDeliveryCount', score: 1 },
    { name: 'landZoneSuccess', score: 1 },
    { name: 'deductPoints', score: -1 },
  ],
  fire: [
    { name: 'successTakeoff', score: 1 },
    { name: 'obstaclePass', score: 1 },
    { name: 'cityPass', score: 1 },
    { name: 'fireDetection', score: 1 },
    { name: 'waterPickup', score: 1 },
    { name: 'fireExtinguish', score: 1 },
    { name: 'dualConnectionBonus', score: 1 },
    { name: 'deductPoints', score: -1 },
  ],
  obstacle: [
    { name: 'scoreBallNumber', score: 2 },
    { name: 'yellowCardNumber', score: -3 },
    { name: 'redCardNumber', score: -10 },
    { name: 'punishBallNumber', score: -3 },
  ],
  gobang: [
    { name: 'winNumber', score: 1 },
    { name: 'fiveNumber', score: 1 },
    { name: 'winPoint', score: 1 },
    { name: 'foulNumber', score: 1 },
    { name: 'sumPoint', score: 1 },
  ],
  drone: [
    { name: 'winNumber', score: 1 },
    { name: 'winPoint', score: 1 },
    { name: 'foulNumber', score: 1 },
    { name: 'sumPoint', score: 1 },
  ],
}

function count(fields, row) {
  // 计算总分
  return fields.reduce(
    (total, field) => total + Number(row[field.name] || 0) * field.score,
    0
  )
}

export function calculateScore(row, type) {
  // 灭火和物流搬运赛 计算总分
  const fields = defaultScore[type]
  return count(fields, row)
}

export function totalPoints(row) {
  // 极速任务赛 计算积分（除荣誉值之外所有分数）
  const fields = defaultScore.obstacle
  return count(fields, row)
}
